package com.example.demo.jpa.service.impl;

import com.example.demo.jpa.dao.SolitaireStatisticsMapper;
import com.example.demo.jpa.entity.Solitaire;
import com.example.demo.jpa.entity.SolitaireStatistics;
import com.example.demo.jpa.entity.jsonobj.SolitaireConfig;
import com.example.demo.jpa.entity.vo.SolitaireStatisticsVo;
import com.example.demo.jpa.service.SolitaireStatisticsService;
import com.example.demo.util.JSONUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created with Software IntelliJ IDEA
 * <p>
 *
 * @author Administrator  2019/9/15 13:26
 * @version 1.0
 */
@Service
public class SolitaireStatisticsServiceImpl implements SolitaireStatisticsService {
    private static final Logger LOGGER = LoggerFactory.getLogger(SolitaireStatisticsServiceImpl.class);
    @Autowired
    private SolitaireStatisticsMapper solitaireStatisticsMapper;

    @Override
    public int deleteByPrimaryKey(Long id) {
        solitaireStatisticsMapper.deleteById(id);
        return 1;
    }

    @Override
    public int insertSelective(SolitaireStatistics record) {
        // record.setId(IDGenerator.nextId());
        record.setCreateDate(new Date());
        record.setUpdateDate(record.getCreateDate());
        solitaireStatisticsMapper.save(record);
        return 1;
    }

    @Override
    public int updateByPrimaryKeySelective(SolitaireStatistics record) {
        record.setUpdateDate(new Date());
        solitaireStatisticsMapper.save(record);
        return 1;
    }

    @Override
    public SolitaireStatistics selectByPrimaryKey(Long id) {
        return solitaireStatisticsMapper.findById(id).orElse(null);
    }

    @Override
    public int deleteBySolitaireId(Long solitaireId) {
        SolitaireStatistics solitaire = new SolitaireStatistics();
        solitaire.setSolitaireId(solitaireId);
        solitaireStatisticsMapper.delete(solitaire);
        return 1;
    }

    @Override
    public SolitaireStatistics selectByParams(Long userId, Long solitaireId) {
        Map<String, Object> params = new HashMap<>();
        params.put("userId", userId);
        params.put("solitaireId", solitaireId);
        List<SolitaireStatisticsVo> list = null;
        return list.isEmpty() ? null : list.get(0);
    }

    @Override
    public List<SolitaireStatisticsVo> selectByParams(Long solitaireId) {
        Map<String, Object> params = new HashMap<>();
        params.put("solitaireId", solitaireId);
        return selectByParams(params);
    }

    @Override
    public List<SolitaireStatisticsVo> selectByParams(Map<String, Object> params) {
//        List<SolitaireStatisticsVo> list = solitaireStatisticsMapper.selectByParams(params);
//        for (SolitaireStatisticsVo vo : list) {
//            vo.setValue(JSONUtil.parseJson(vo.getJsonField(), SolitaireConfig.class));
//            vo.setJsonField(null);
//        }
//        return list;
        return null;
    }

    @Override
    public int selectCountByParams(Map<String, Object> params) {
        // return solitaireStatisticsMapper.selectCountByParams(params);
        return 0;
    }
}
